package com.zhenhao.xsq.utils;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.bigkoo.alertview.AlertView;
import com.bigkoo.alertview.OnItemClickListener;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.orhanobut.logger.Logger;
import com.zhenhao.xsq.R;
import com.zhenhao.xsq.adapter.BottomAdapter;
import com.zhenhao.xsq.view.BaseDialog;

import java.util.List;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

public class DialogUtils {

    public static void showAlerDialog(Context context, String title, String[] strs, OnItemClickListener
            itemClickListener) {
        new AlertView(title, null, "取消", strs, null, context, AlertView.Style.ActionSheet, itemClickListener).show();

    }

    public static void showCommonDialog(Context context, String content, final
    onCommonDialogListene listene) {
        final BaseDialog baseDialog = new BaseDialog(context);
        baseDialog.setCancelable(false);
        baseDialog.setTitle("提示");
        baseDialog.setContent(content);
        baseDialog.setCancelListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                baseDialog.dismiss();
            }
        });
        baseDialog.setSureListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                baseDialog.dismiss();
                listene.onCommonDialogListene(view);
            }
        });
        baseDialog.show();
    }

    public static void showBottomDialog(Context context, String title, List<String> list, final
    onTreeSelect select) {
        final BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(context);
        bottomSheetDialog.setContentView(R.layout.dialog_bottom); //给布局设置透明背景色
        bottomSheetDialog.getDelegate().findViewById(R.id
                .design_bottom_sheet).setBackgroundColor(context.getResources().getColor(android
                .R.color.transparent));
        bottomSheetDialog.setCancelable(false);
        RecyclerView viewById = bottomSheetDialog.findViewById(R.id.rv);
        ImageView cancle = bottomSheetDialog.findViewById(R.id.img_cancle);
        TextView tvTitle = bottomSheetDialog.findViewById(R.id.tv_title);
        if (!TextUtils.isEmpty(title)) {
            tvTitle.setText(title);
        }
        cancle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                bottomSheetDialog.dismiss();
            }
        });
        viewById.setLayoutManager(new LinearLayoutManager(context));
        BottomAdapter adapter = new BottomAdapter(list);
        viewById.setAdapter(adapter);
        adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                bottomSheetDialog.dismiss();
                select.onTreeSelect((String) adapter.getData().get(position), position);
            }
        });
        bottomSheetDialog.show();
    }

    /**
     * 选择当前登录房屋
     *
     * @param context
     * @param list
     * @param select
     */
    public static void showFwDialog(Context context, List<String> list, final
    onTreeSelect select) {
        final BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(context);
        bottomSheetDialog.setContentView(R.layout.dialog_fw); //给布局设置透明背景色
        bottomSheetDialog.getDelegate().findViewById(R.id
                .design_bottom_sheet).setBackgroundColor(context.getResources().getColor(android
                .R.color.transparent));
        bottomSheetDialog.setCancelable(false);
        RecyclerView viewById = bottomSheetDialog.findViewById(R.id.rv);
        CheckBox ckb = bottomSheetDialog.findViewById(R.id.ckb);
        viewById.setLayoutManager(new LinearLayoutManager(context));
        BottomAdapter adapter = new BottomAdapter(list);
        viewById.setAdapter(adapter);
        adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                bottomSheetDialog.dismiss();
                select.onTreeSelect((String) adapter.getData().get(position), position);
            }
        });
        ckb.setChecked(SpSaveUtils.getCheckFw());
        ckb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                Logger.i("--------" + b);
                SpSaveUtils.putCheckFw(b);
            }
        });
        bottomSheetDialog.show();
    }



    public interface OnOptionSelect {
        void onOptionsSelect(int option);
    }

    public interface onZqTimeSelect {
        void onZqTimeSelect(String str, int option);
    }

    public interface onRoomSelect {
        void onRoomSelect(String str);

    }

    public interface onTreeSelect {
        void onTreeSelect(String str, int position);
    }

    public interface onCommonDialogListene {
        void onCommonDialogListene(View view);
    }

    public interface onBleDialogListene {
        void onBleDialogListene(View view);
    }
}
